#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
using namespace std;
int main()
{
	int t,ans;
	scanf("%d",&t);
	while(t--)
	{
		int a,b;
		scanf("%d %d",&a,&b);
		if(a<b) ans = b-a;
		else 
		{
			if(a%b)
				ans = b-a%b;
			else ans = 0;
		}
		printf("%d\n",ans);
	}
} 
